package ysq.xyg.web.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.web.model.po.WebLinker;
import ysq.xyg.web.model.vo.WebLinkerVo;
import ysq.xyg.web.service.WebLinkerService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
 * 网站模块-外链接controller层
 *
 * @author shengQiang yu
 * @date 2019-8-19 13:48:38
 */
@RestController
public class WebLinkerController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebLinkerController.class);
    @Resource
    private WebLinkerService webLinkerService;

    private WebLinker webLinker;

    /**
     * 分页查询
     *
     * @param webLinkerVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-8-19 13:48:38
     */
    @BaseLog(module = "网站模块",className = "外链接",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webLinker/page",method = RequestMethod.POST)
    public ReturnEntity page(WebLinkerVo webLinkerVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = webLinkerService.page(webLinkerVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-8-19 13:48:38
     */
    @RequestMapping(value = "/webLinker/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webLinkerUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webLinker = webLinkerService.selectByPrimaryKey(id);
            view.addObject("webLinker", webLinker);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-8-19 13:48:38
     */
    @BaseLog(module = "网站模块",className = "外链接",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webLinker/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webLinkerService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webLinkerVo Vo对象
     * @author shengQiang yu
     * @date 2019-8-19 13:48:38
     */
    @BaseLog(module = "网站模块",className = "外链接",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webLinker/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebLinkerVo webLinkerVo){
        return webLinkerService.addOrUpdate(webLinkerVo,acceptCurrentUser(request));
    }
}